package main

import (
	_ "HTchoujiang/routers"
	_ "github.com/go-sql-driver/mysql"
	_ "choujiang/models"
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/orm"
	"os"
	"HTchoujiang/crontab"
)

func init() {
	env := os.Getenv("ENV_TIZHIZAIXIAN")
	if env == "ONLINE" {
		orm.RegisterDataBase("default", "mysql", "root:myDehexin2018mysql@tcp(localhost:3306)/choujiang?charset=utf8&loc=Local")
	} else if env == "ONLINETEST" {
		orm.RegisterDataBase("default", "mysql", "root:myDehexin2018mysql@tcp(localhost:3306)/choujiang?charset=utf8&loc=Local")
	} else {
		orm.RegisterDataBase("default", "mysql", "root:vrjiaju2016mysql@tcp(localhost:3306)/choujiang?charset=utf8&loc=Local")
	}
	orm.RunSyncdb("default", false, true)
}

func main() {
	setStaticPath()
	beego.BConfig.WebConfig.Session.SessionOn = true
	go crontab.StartCron()
	beego.Run()
}

func setStaticPath() {
	beego.SetStaticPath("/js", "views/js")
	beego.SetStaticPath("/img", "views/img")
	beego.SetStaticPath("/css", "views/css")
	beego.SetStaticPath("/docs", "views/docs")
	beego.SetStaticPath("/fonts", "views/fonts")
	beego.SetStaticPath("/plugins", "views/plugins")
	beego.SetStaticPath("/assets", "views/assets")
	beego.SetStaticPath("/themes", "views/themes")
	beego.SetStaticPath("/third-party", "views/third-party")
	beego.SetStaticPath("/lang", "views/lang")

	beego.SetStaticPath("/uploads", beego.AppConfig.String("uploadspath"))
}
